import { defineStore } from "pinia";
// import piniaPersistConfig from "@/stores/helper/persist";
import {
  GetSelWeiHaiYinSuport,
  GetSelWeiHaiYinSuDataport,
  GetAllYuanQuSelport,
  GetSelGuoBiaoDuiYinItemport
} from "@/api/modules/user";

export const dataWeihu = defineStore({
  id: "dataWeihu",
  state: (): any => ({
    WeiHaiYinSudata: [],
    arbitrage: "",
    GetSelWeiHaiYinSuData: [],
    Hospitalinquiry: [],
    leibie: "",
    name: "",
    sole: "",
    judgePortfolioproject: "",
    Copyitem: [],
    excessive: {},
    zuhexiangmu: {},
    Provincialplatform: {},
    // 储存对应本地项目
    Correspondinglocal: [],
    variety: ""
  }),
  actions: {
    varietyChange(item) {
      this.variety = item;
      console.log(this.variety);
    },
    // 储存单条省平台标准项目的数据
    ProvincialplatformChange(item) {
      this.Provincialplatform = item;
      console.log(this.Provincialplatform);

      const data = {
        strGuoBiaoZuHeXiangMuDaiMa: item.ZuHeXiangMuBianMa
      };
      GetSelGuoBiaoDuiYinItemport(data).then((res: any) => {
        if (res.Success == 0) {
          this.Correspondinglocal = res.Data;
          console.log(this.Correspondinglocal);
        }
      });
    },
    // 存储组合项目的单条数据
    zuhexiangmuChange(item) {
      this.zuhexiangmu = item;
      console.log(this.zuhexiangmu);
    },
    // 复制项目
    CopyitemChange(item: any) {
      this.Copyitem = item;
      console.log(this.Copyitem);
    },
    // 危害因素id
    soleChange(item: any) {
      this.sole = item;
    },
    // 判断哪个界面的组合项目
    judgePortfolioprojectChange(item: string) {
      this.judgePortfolioproject = item;
    },
    workingarea(leibie: any, name: "any") {
      this.leibie = leibie;
      this.name = name;
    },
    // 初始化请求危害因素数据
    WeiHaiYinSuChange(kind?: string, PYM?: string) {
      console.log(kind, PYM);
      let data = {
        strZhongLei: this.leibie,
        strName: this.name
      };
      GetSelWeiHaiYinSuport(data).then((res: any) => {
        console.log(res);
        if (res.Success == 0) {
          this.WeiHaiYinSudata = res.Data;
        }
      });
    },
    // 储存岗期
    arbitrageChange(GQ: string) {
      console.log(GQ);
      this.arbitrage = GQ;
    },
    // 存储表格当前行数据
    excessiveChange(item) {
      console.log(item);
      this.excessive = item;
    },
    // 查询危害因素项目、检查内容、监护依据、国标内容
    GetSelWeiHaiYinSuDataChange() {
      console.log(this.excessive.WeiHaiYinSuID, "111", this.excessive.GuoBiaoDaiMa, "222");

      if (this.excessive.WeiHaiYinSuID == "" || this.excessive.WeiHaiYinSuID == undefined) {
        return;
      } else {
        console.log(this.excessive);
        let data = {
          strWeiHaiYinSuId: this.excessive.WeiHaiYinSuID,
          strGangQi: this.arbitrage,
          strWeiHaiYinSuGuoBiaoDaiMa: this.excessive.GuoBiaoDaiMa
        };
        GetSelWeiHaiYinSuDataport(data).then((res: any) => {
          if (res.Success == 0) {
            this.GetSelWeiHaiYinSuData = res.Data;
            console.log(this.GetSelWeiHaiYinSuData);
          }
        });
      }
    },
    // 查询院区
    HospitalinquiryChange() {
      GetAllYuanQuSelport().then((res: any) => {
        if (res.Success == 0) {
          this.Hospitalinquiry = res.Data;
          console.log(this.Hospitalinquiry);
        }
      });
    }
  }
  // persist: piniaPersistConfig("dataWeihu")
});
